export function dicFormatter(options = [], val) {
  let find = deepFind(options, val)
  return find?.label || val
}

const deepFind = (options, val) => {
  for (let i = 0; i < options.length; i++) {
    let item = options[i]
    if (item.value == val) return item
    if (item.children && item.children.length) {
      let res = deepFind(item.children, val)
      if (res) return res
    }
  }
}

export function matchProjectState(val, options) {
  let find = options.find(item => item.value === val)
  return find
}

export const ProjectFormType = {
  ADD: '添加',
  DETAIL: '详情',
  REVIEW: '审核',
}

export const ProjectListType = {
  LIST: '添加',
  REVIEW_LIST: '审核',
}

export const ApplyApproveType = {
  UPLOAD: '上传文件',
  FORM: '表单',
  SAFE_EVALUATE: '安全评估单',
  DATE: '时间',
}

export const stateEnum = {
  REJECT: '1',
  PENDING: '2', // 审核中
  UNDER_CONSTRUCTION: '8', // 施工中
  DELAY_APPROVING: '9',//待延期审批
  HANDOVER_APPROVING: '10',//待验收
  WAIT_DEPOSIREFUND: '11', // 待退押金
  EXITED: '12', //已退场
  EXTENSIONING: '13', // 即将延期
  EXTENSIONED: '14', // 已延期
}

export const personTypeEnum = [
  {label: '特种作业人员', value: '1'},
  {label: '施工人员', value: '2'},
]
export const personSourceEnum = [
  {label: '内部人员', value: '1'},
  {label: '外部人员', value: '2'},
]
export const nodeTypeEnum = [
  {label: '填写节点', value: '1'},
  {label: '审批节点', value: '2'},
]
export const approveNodeTypeEnum = [
  {label: '上传培训记录', value: '1'},
  {label: '审批培训记录', value: '2'},
]

// 审批类型，1 ：串行审批 2：并行或签 3 并行 会签
export const approvalTypeTree = [
  {
    label: '并行审批',
    children: [
      {
        label: '会签(需所有负责人通过)',
        value: 3
      },
      {
        label: '或签(一名负责人通过或驳回即可)',
        value: 2
      },
    ]
  },
  {
    label: '串行审批',
    value: 1
  }
]
